/*
** kbdready.c
**
** Pictor, Version 1.51, Copyright (c) 1992-94 SoftCircuits
** Redistributed by permission.
*/

#include "pictor.h"

extern int _PL_pushedkey;


/*
** Returns the next available keystroke without removing it from
** the keyboard buffer. Returns 0 if no keystrokes available.
*/
int kbdready(void)
{
	int key = 0;

	if(_PL_pushedkey) {
		key = _PL_pushedkey;
	}
	#ifdef __WATCOMC__
		_asm{
				mov   ah,01h
				int   16h
				jz    end_kbdready
				cmp   ax,1
				adc   ax,0
				mov   key,ax
				end_kbdready:
			};
	#else
	else {
		/* use in-line assembler to correctly */
		/* detect an empty keyboard buffer */
		_asm	mov   ah,01h
		_asm	int   16h
		_asm	jz    end_kbdready
		_asm	cmp   ax,1
		_asm	adc   ax,0
		_asm	mov   key,ax
	}
	end_kbdready:
	#endif
		

	return(key);

} /* kbdready */
